fn main() {
	// sorting arrays of all kinds is very simple and intuitive
	// special variables a and b are used when providing a custom sorting condition
	mut numbers := [1, 2, 3]
	numbers.sort()
	println(numbers)
	numbers.sort(a > b)
	println(numbers)
	
	mut users := [User{21, 'Bob'}, User{20, 'Zarkon'}, User{25, 'Alice'}]
	users.sort(a.age < b.age) // sort by User.age int field
	println(users)
	users.sort(a.name > b.name) // reverse sort by User.name string field
	println(users)
	
	custom_sort_fn := fn (a &User, b &User) int {
		// return -1 when a comes before b
		// return 0, when both are in same order
		// return 1 when b comes before a
		if a.name == b.name {
			if a.age < b.age {
				return 1
			}
			
			if a.age > b.age {
				return -1
			}
			return 0
		}
		
		if a.name < b.name {
			return -1
		} else if a.name > b.name {
			return 1
		}
		
		return 0
	}
	
	// sorting on multiple fields at the same time by custom sorting rules
	users.sort_with_compare(custom_sort_fn)
	println(users)
}

struct User {
	age  int
	name string
}
